/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-04-14
 * Time: 10:06
 */
public class Main {
    public static void main(String[] args) {
        // 1. 创建StringBuilder对象
        StringBuilder sbuil = new StringBuilder("Java");

        // 2. append()方法：追加内容
        sbuil.append(" is");
        sbuil.append(" fun!");
        System.out.println("追加后：" + sbuil);// 追加后：Java is fun!

        // 3. insert()方法：在指定位置插入
        sbuil.insert(5, "really ");
        System.out.println("插入后：" + sbuil);// 插入后：Java really is fun!

        // 4. delete()方法：删除子串
        sbuil.delete(5, 11); // [5,11)区间
        System.out.println("删除后：" + sbuil); // 删除后：Java  is fun!

        // 5. replace()方法：替换字符串
        sbuil.replace(0, 4, "C++"); // 将索引 [0,4) 替换为 "XYZ"
        System.out.println(sbuil);  // 输出: C++  is fun!

        // 5. reverse()方法：反转字符串
        sbuil.reverse();
        System.out.println("反转后：" + sbuil); // 反转后：!nuf si  ++C
    }
}
